/**
 * Copyright (C), 2018 store
 * Encoding: UTF-8
 * Date: 19-12-11 上午11:20
 * History:
 */
package com.swak.frame.excel.bo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;


/**
 * RowObject.java
 * 
 * @author ColleyMa
 * @version 19-12-11 上午11:20
 */
public class RowObject {
    private int row;
    private List<CellObject> rowData;

    public List<CellObject> getRowData() {
        return rowData;
    }

    public void setRowData(List<CellObject> rowData) {
        this.rowData = rowData;
    }

    public int getRow() {
        return row;
    }

    public void setRow(int row) {
        this.row = row;
    }

    public Map<String, String> getCellValuesMap() {
        Map<String, String> cellData = Maps.newHashMap();
        cellData.put("row", String.valueOf(row));

        if ((rowData != null) && (rowData.size() > 0)) {
            for (CellObject cell : rowData) {
                String key = cell.getPropName();
                String value = cell.getCellVal();

                if (!StringUtils.isEmpty(key)) {
                    cellData.put(StringUtils.trim(key), StringUtils.trim(value));
                }
            }
        }

        return cellData;
    }

    public List<String> getCellValues() {
        List<String> cellData = Lists.newArrayList();

        if ((rowData != null) && (rowData.size() > 0)) {
            for (CellObject cell : rowData) {
                cellData.add(cell.getCellVal());
            }
        }

        return cellData;
    }

    public CellObject getCellObjectByName(String propName) {
        if ((rowData != null) && (rowData.size() > 0)) {
            for (CellObject cell : rowData) {
                String name = cell.getPropName();

                if (name.equals(propName)) {
                    return cell;
                }
            }
        }

        return null;
    }

    public Map<String, CellObject> cellObject2Map() {
        Map<String, CellObject> cellData = new HashMap<String, CellObject>();

        if ((rowData != null) && (rowData.size() > 0)) {
            for (CellObject cell : rowData) {
                String key = cell.getPropName();

                if (!StringUtils.isEmpty(key)) {
                    cellData.put(key, cell);
                }
            }
        }

        return cellData;
    }
}
